import { ref } from 'vue'
import { defineStore } from 'pinia'
import { api } from '@/js/ajax'
const EMRET = {
  tbUser: {},
  tbUserInfo: {},
  tbRole: {},
  exInfo: {},
}

export const userstore = defineStore('userstrore', () => {
  const islogin = ref(false)
  const userinfo = ref(EMRET)
  const userlogo = ref('')

  const updateUserInfo = (cb) => {
    api.get('/auth', {}, (data) => {
      if (data.success) {
        userinfo.value = data.data
        userlogo.value = api.userlogo(data.data.tbUser.uid)
      } else {
        userinfo.value = EMRET
        userlogo.value = ''
      }

      islogin.value = data.success
      cb(islogin.value)
    })
  }

  return {
    islogin,
    userinfo,
    userlogo,
    updateUserInfo,
  }
})
